<!--
 * @Descripttion: 
 * @version: 
 * @Author: congsir
 * @Date: 2023-12-21 11:11:20
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2024-01-03 17:15:39
-->
<template>
  <div class="content">
    <div class="_content">
      <div class="jm">
        <img
          src=""
          alt=""
          srcset=""
        />
        银行级别加密,保护您的数据隐私
      </div>
      <div class="payDes" style="position: relative">
        <img src="../assets/index_image/payDes-e9dc38aa.png" alt="" srcset="" />
        <div>
          <div @click="navigateToDetail()" class="kefu">查询记录</div>
        </div>
      </div>
      <div class="_fx">
        😟您的数据报告可能存在<span style="font-weight: bold"> 5 </span>项风险
      </div>
      <div class="bgpd">
        <div class="pay_content">
          <div class="a-flex">
            <img
              src="../assets/index_image/cWRTCcv6i0LL.png"
              alt=""
              srcset=""
            />
            <div class="info">
              <div class="cardId">姓名：{{ data.info.realName }}</div>
              <div class="cardId">性别：{{ data.info.sex }} | 年龄：{{ data.info.age }}</div>
              <div class="cardId">证件号：{{ data.info.idCard }}</div>
              <div class="cardId">户籍地：{{ data.info.prov }}</div>
            </div>
            <button
              class="css-1qb1s0s ant-btn ant-btn-default getReport"
              type="button"
              @click="pay()"
            >
              <span>获取报告</span>
            </button>
          </div>
          <div class="pay_item">
            <img
              src="../assets/index_image/iVBORw0KG.png"
              alt=""
              srcset=""
              width="16"
            />
            <div class="zx-name">身份信息</div>
            <div class="zx-right">
              <span class="not-fx right-txt">待解锁</span
              >
              <i class="icon iconfont icon-suo"></i>
            </div>
          </div>
          <div class="pay_item">
            <img
              src="../assets/index_image/iVBORw0KG.png"
              alt=""
              srcset=""
              width="16"
            />
            <div class="zx-name">司法风险</div>
            <div class="zx-right">
              <span class="not-fx right-txt">待解锁</span
              ><i class="icon iconfont icon-suo"></i>
            </div>
          </div>
          <div class="pay_item">
            <img
              src="../assets/index_image/iVBORw0KG.png"
              alt=""
              srcset=""
              width="16"
            />
            <div class="zx-name">欺诈风险</div>
            <div class="zx-right">
              <span class="not-fx right-txt fx-true">可能存在风险</span
              ><span class="not-fx right-txt">待解锁</span
              ><i class="icon iconfont icon-suo"></i>
            </div>
          </div>
          <div class="pay_item">
            <img
              src="../assets/index_image/iVBORw0KG.png"
              alt=""
              srcset=""
              width="16"
            />
            <div class="zx-name">失信信息</div>
            <div class="zx-right">
              <span class="not-fx right-txt fx-true">可能存在风险</span
              ><span class="not-fx right-txt">待解锁</span
              ><i class="icon iconfont icon-suo"></i>
            </div>
          </div>
          <div class="pay_item">
            <img
              src="../assets/index_image/iVBORw0KG.png"
              alt=""
              srcset=""
              width="16"
            />
            <div class="zx-name">多头逾期</div>
            <div class="zx-right">
              <span class="not-fx right-txt fx-true">可能存在风险</span
              ><span class="not-fx right-txt">待解锁</span
              ><i class="icon iconfont icon-suo"></i>
            </div>
          </div>
          <div class="pay_item">
            <img
              src="../assets/index_image/iVBORw0KG.png"
              alt=""
              srcset=""
              width="16"
            />
            <div class="zx-name">黑名单风险</div>
            <div class="zx-right">
              <span class="not-fx right-txt fx-true">可能存在风险</span
              ><span class="not-fx right-txt">待解锁</span
              ><i class="icon iconfont icon-suo"></i>
            </div>
          </div>
          <div class="more">
            <svg class="" style="width: 12px; height: 12px">
              <use xlink:href="#icon-more" fill=""></use></svg
            >更多模块解锁后查看
          </div>
        </div>
        <div class="payBtn" @click="pay()">
          <button
            class="css-1qb1s0s ant-btn ant-btn-primary ant-btn-block"
            type="button"
          >
            <!----><span
              ><span
                >解锁报告仅 ￥{{
                  parseFloat(data.web_info.price).toFixed(2)
                }}元</span
              ><span class="through">￥100</span></span
            >
          </button>
        </div>
        <div class="b_t">
          <div class="b1">已有2362008人优化了自己的信用</div>
          <div>为保证您的信息安全，请确保本人查询</div>
          <div>支付完成0~2分钟内生成报告结果</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {
  reactive,
  onMounted,
  onBeforeMount,
  watch,
  defineProps,
  defineEmits,
  onUnmounted,
} from "vue";
import request from "../api/reuests";
import { setItem, getItem, removeItem } from "../uint/localStorage.js";
import IdCardValid from '../uint/IdCardvalid.js';
import { useRouter, useRoute } from "vue-router"; //引入路由
const router = useRouter();
const route = useRoute();
const data = reactive({
  outTipsShow: false, // 红包页面控制状态
  info: {},
  web_info: {}, //公司名称，价格，红包金额
});

const pay = () => {
  request({
    url: "/index/createOrder",
    method: "POST",
    data: {
      info: data.info,
      total_fee: data.web_info.price,
    },
  })
    .then((res) => {
      let res_data1 = res.data;
      setItem("order_insert", res_data1); // 支付信息
      if (res.code == 200) {
        setItem("applyPay", 1);
        Bulletframe();
      } else {
        ElMessage.error(res.msg);
      }
    })
    .catch((err) => {
      console.error(err);
    });
};
// 获取公司名称，价格，红包金额
const getprice = () => {
  request({ url: "/index/getinfo", method: "GET" })
    .then((res) => {
      if (res.code == 200) {
        data.web_info = res.data;
      }
    })
    .catch((err) => {
      console.error(err);
    });
};

// 设置红包页面状态
const browserBack = () => {
  if (data.web_info.yhq > 0) {
    data.outTipsShow = true;
  }
};

// 弹框组件
const open = () => {
  ElMessageBox.confirm("是否已完成支付？进入查询记录可查看报告", "支付确认", {
    confirmButtonText: "已支付",
    cancelButtonText: "未支付",
    type: "warning",
    center: true,
  })
    .then(() => {
      //确认
      let order_insert = getItem("order_insert");
      request({
        url: "/index/getOrderStatus",
        method: "POST",
        data: {
          info: data.info,
          out_trade_no: order_insert.out_trade_no,
        },
      })
        .then((res) => {
          if (res.data.status) {
            ElMessage({
              message: "支付成功，正在前往查看报告...",
              type: "success",
            });
            router.push({
              path: "/list",
              query: {
                id: order_insert.insert_id,
              },
            });
            removeItem("order_insert");
            return false;
          } else {
            ElMessage.error("支付失败");
            return false;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    })
    .catch(() => {
      // 否定
      ElMessage.error("支付失败");
      return false;
    });
};
// 弹框组件
const Bulletframe = () => {
	// const baseUrlApi = 'https://kk.cx5.top' 
	
  ElMessageBox.confirm(
    "请在支付宝支付完成后，0~2分钟内生成报告结果。",
    "支付提醒",
    {
      confirmButtonText: "确认",
      cancelButtonText: "取消",
      type: "warning",
      center: true,
      showCancelButton:false,
    }
  )
    .then(() => {
      //确认
      removeItem("applyPay");
      open();
      let order_insert = getItem("order_insert");
      window.open(
        // baseUrlApi + 
		"/index/pay?out_trade_no=" +
          order_insert.out_trade_no,
        "_blank"
      );
    })
    .catch(() => {
      // 否定
      ElMessage.error("支付失败");
      return false;
    });
};
const navigateToDetail = (id) => {
  router.push("/historyRecord");
};
onMounted(() => {
  window.scrollTo(0, 0);
  data.info = getItem("info"); // 个人信息，身份证号，姓名，手机号
  data.web_info = getItem("web_info"); //  获取公司名称，价格，红包金额
  getprice();
  // // 获取红包页面
  // window.history.pushState(null, null, document.URL);
  // window.addEventListener("popstate", browserBack);

  if (1 == getItem("applyPay")) {
    removeItem("applyPay");
    open();
  }
});
// 在组件卸载之前执行
// onUnmounted(() => {
//   if (data.web_info.yhq > 0) {
//     window.removeEventListener("popstate", browserBack);
//   }
//   console.log("unmounted!");
// });
</script>

<style lang="less" scoped>
.icon-suo{
  font-size: 22px;
    color: #9b9797;
}
.content {
  min-height: 100vh;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  background-image: url(../assets/index_image/h5-18255dc0.png);
  background-size: cover;
}
._content {
  margin: 0px auto;
  max-width: 750px;
  box-shadow: rgb(219, 207, 173) 0px 0px 15px 4px;
  min-height: 100vh;
  box-sizing: border-box;
  background-image: url(../assets/index_image/payBg-82767c7b.png);
  background-size: cover;
  display: flex;
  flex-direction: column;
}
.jm {
  display: flex;
  flex-direction: row;
  background-color: rgb(19, 137, 248);
  align-items: center;
  color: rgb(255, 255, 255);
  padding: 8px 16px;
  box-sizing: border-box;
  font-size: 13px;
  img {
    width: 12px;
    margin-right: 8px;
  }
}
.payDes {
  padding: 40px 0px;
  text-align: center;
  img {
    width: 340px;
    margin: 0px auto;
  }
}
.kefu {
  position: absolute;
  bottom: -15px;
  right: 0px;
  width: 65px;
  height: 26px;
  text-align: center;
  line-height: 26px;
  font-size: 12px;
  color: rgb(255, 255, 255);
  z-index: 1;
  cursor: pointer;
  background: 0% 0% / 65px 31px rgb(242, 154, 44);
  border-radius: 20px 0px 0px 20px;
  border-width: 0.5px 0px 0.5px 0.5px;
  border-style: solid solid solid;
  border-color: rgb(255, 255, 255) rgb(255, 255, 255) rgb(255, 255, 255);
  border-image: initial;
  border-right: 0px;
}
._fx {
  color: rgb(255, 255, 255);
  text-align: center;
  margin-bottom: 10px;
  font-size: 14px;
}
.bgpd {
  background: rgb(249, 249, 249);
  flex-grow: 1;
  margin-top: 100px;
  padding-top: 100px;
  .pay_content {
    position: relative;
    margin-top: -200px;
    box-shadow: rgba(0, 0, 0, 0.15) 0px 0px 8px;
  }

  .pay_item {
    display: flex;
    align-items: center;
    position: relative;
    border-bottom: 1px solid rgb(229, 229, 229);
    padding: 15px 0px;
    font-size: 15px;
  }
  .more {
    color: rgb(0, 130, 240);
    text-align: center;
    margin-top: 15px;
    cursor: pointer;
    font-size: 13px;
  }
}
.a-flex {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(229, 229, 229);
  padding-bottom: 15px;
  position: relative;
  img {
    width: 60px;
    height: 60px;
  }
  .info {
    padding-left: 10px;
  }
}
.pay_content {
  background-color: rgb(255, 255, 255);
  border-radius: 15px;
  width: calc(100% - 40px);
  margin: 0px auto;
  padding: 20px;
  box-sizing: border-box;
}
.cardId {
  font-size: 12px;
  margin-bottom: 1px;
}
.zx-name {
  margin-left: 8px;
}
.zx-right {
  position: absolute;
  right: 10px;
  top: 16px;
  font-size: 14px;
  color: rgb(155, 151, 151);
  .right-txt {
    margin-right: 10px;
  }
  .suo {
    position: relative;
    top: 2px;
  }
  .fx-true {
    color: red;
    font-size: 12px;
  }
}
.more {
  color: rgb(0, 130, 240);
  text-align: center;
  margin-top: 15px;
  cursor: pointer;
  font-size: 13px;
  svg {
    transform: rotate(90deg);
    margin-right: 6px;
    position: relative;
    top: 1px;
  }
}
.payBtn {
  width: calc(100% - 40px);
  margin: 15px auto 0px;
  button {
    height: 38px;
  }
}
.ant-btn {
  outline: none;
  position: relative;
  display: inline-block;
  font-weight: 400;
  white-space: nowrap;
  text-align: center;
  background-image: none;
  background-color: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  user-select: none;
  touch-action: manipulation;
  line-height: 1.5714285714285714;
  color: rgba(0, 0, 0, 0.88);
}
.ant-btn {
  font-size: 14px;
  height: 32px;
  padding: 4px 15px;
  border-radius: 6px;
}
.ant-btn-primary {
  color: #fff;
  background-color: #1677ff;
  box-shadow: 0 2px 0 rgba(5, 145, 255, 0.1);
}
.ant-btn.ant-btn-block {
  width: 100%;
}
.getReport {
  height: 38px;
  background: linear-gradient(270deg, #196dff, #a2c4ff);
  border-radius: 22px;
  box-shadow: 0 1px 3px #b8d2ff;
  font-size: 15px;
  font-weight: 400;
  text-align: center;
  color: #fff;
  position: absolute;
  right: -10px;
  top: 9px;
  cursor: pointer;
  border: 0;
}
.getReport:hover {
  opacity: 0.9;
  border: 0;
}
.through {
  margin-left: 10px;
  text-decoration: line-through;
  font-size: 12px;
}
.b_t {
  color: rgb(102, 102, 102);
  font-size: 12px;
  text-align: center;
  margin: 20px 0px;
  .b1 {
    margin-bottom: 15px;
  }
}
@media screen and (max-width: 1199px) {
  .payDes {
    padding: 18px 0px 12px;
    img {
      width: 250px;
    }
  }
}
@media screen and (min-width: 750px) {
  .a-flex {
    .info {
      display: flex;
      flex-wrap: wrap;
      padding-left: 15px;
    }
  }
  .cardId {
    width: 50%;
    margin-bottom: 5px;
  }
}
</style>
